package com.mantru.iotpot.Tools;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;

import com.mantru.iotpot.R;

public class LoadingDialogUtil {
    private static Dialog loadingDialog;

    public static void showLoadingDialog(Context context) {
        if (loadingDialog == null) {
            loadingDialog = new Dialog(context);
            loadingDialog.setContentView(R.layout.loading_dialog);
            loadingDialog.setCancelable(false); // 点击外部不可取消
            // 设置窗口背景透明
            if (loadingDialog.getWindow() != null) {
                loadingDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
            }
        }
        loadingDialog.show();
    }

    public static void closeLoadingDialog() {
        if (loadingDialog != null && loadingDialog.isShowing()) {
            loadingDialog.dismiss();
            loadingDialog = null;
        }
    }
}
